/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package programaobf;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 *
 * @author MSK
 */
public class toprep1 {
    public static String nwl = System.getProperty("line.separator");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    DataOutputStream dos = null;
    toprep1(File coloap, File trep1) throws FileNotFoundException, IOException{
          if(coloap.exists()){
          fis = new FileInputStream(coloap);
          bis = new BufferedInputStream(fis);
          dis = new DataInputStream(bis);
          fos = new FileOutputStream(trep1);
          bos = new BufferedOutputStream(fos);
          dos = new DataOutputStream(bos);
          Matcher prom = null;
          int i=0;
          String[] repm = {"/promo/mujki","/promo/damski","/promo/teen","/promo/detski"};
          //int counm=1,cound=1,coune=1,counr=1;
          //int[] grepm = {counm,cound,coune,counr};
          int[] grepm = {1,1,1,1};
          while (dis.available() != 0 ){
              String barev = (dis.readLine() + nwl);
              String[] rebac = barev.split("[ ]");
              for(i=0;i<repm.length;i++){
              Pattern rep1com = Pattern.compile(repm[i]);
              prom = rep1com.matcher(barev);
              if(prom.find() == true){
              dos.writeBytes(grepm[i]+" "+repm[i]+" "+rebac[0]+nwl);
              grepm[i]++;
              }
            }
          }
          fos.flush();
          dos.flush();
          fos.close();
          bis.close();
          dos.close();
          fis.close();
          bis.close();
          dis.close();
          System.out.println("The file has been written "+trep1);
          }
          else{
            System.out.println("This file is not exist");}

  }
}
